//
//  ZTControlMessageCell.m
//  YSSmartHome
//
//  Created by Yahaong on 16/8/15.
//  Copyright © 2016年 yahaong. All rights reserved.
//

#import "ZTControlMessageCell.h"
#import "OperationModel.h"
#import "YHMarcros.h"
@interface ZTControlMessageCell  ()
@property(nonatomic, strong)UIView *circleView;
@property(nonatomic, strong)UIView *topTimeLine;
@property(nonatomic, strong)UIView *bootomTimeLine;
@property(nonatomic, strong)UILabel *operationLabel;
@end
static NSString *const identifier = @"controlMessageCell";
@implementation ZTControlMessageCell


+ (instancetype)controlMessageCell:(UITableView *)tableView
{
    ZTControlMessageCell*cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];

        
    }
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupUI];
}

- (void)setupUI
{
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self.contentView addSubview:self.circleView];
    [self.circleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.leading.equalTo(self.contentView).offset(80);
        make.width.height.equalTo(8);
    }];
    self.circleView.layer.cornerRadius = 4;
    self.circleView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.topTimeLine];
    [self.topTimeLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.centerX.equalTo(self.circleView);
        make.width.equalTo(2);
        make.bottom.equalTo(self.circleView.bottom);
    }];
    [self.contentView addSubview:self.bootomTimeLine];
    [self.bootomTimeLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.circleView.bottom);
        make.centerX.equalTo(self.circleView);
        make.width.equalTo(2);
        make.bottom.equalTo(self.contentView);
    }];
    [self.contentView addSubview:self.operationLabel];
    [self.operationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.topTimeLine.trailing).offset(30);
        make.centerY.equalTo(self.circleView);
    }];
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

- (void)setOperation:(OperationModel *)operation
{
    _operation = operation;
    NSDate *date =  [NSDate dateWithTimeIntervalSince1970:operation.time];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/BeiJing"];
    [dateFormatter setTimeZone:timeZone];
    [dateFormatter setDateFormat:@"HH:mm"];
    NSString *dateStr = [dateFormatter stringFromDate:date];
    self.operationLabel.text  = [NSString stringWithFormat:@"%@%@",dateStr,_operation.operation];
}
- (void)setCellType:(CellType)cellType
{
    _cellType = cellType;
    switch (cellType) {
        case CellTypeBottom:
        {
            self.topTimeLine.hidden = NO;
            self.bootomTimeLine.hidden = YES;
        }
            break;
        case CellTypeMiddle:
        {
            self.topTimeLine.hidden = NO;
            self.bootomTimeLine.hidden = NO;
        }
            break;
        case CellTypeTop:
        {
            self.topTimeLine.hidden = YES;
            self.bootomTimeLine.hidden = NO;
        }
            break;
        case CellTypeNone:
        {
            self.topTimeLine.hidden = YES;
            self.bootomTimeLine.hidden = YES;
        }
            break;
        default:
            break;
    }
}
#pragma mark - lazy loading
- (UIView *)circleView
{
    if (!_circleView) {
        _circleView = [[UIView alloc]init];
        _circleView.backgroundColor = RGBColor(224, 224, 224);
     
    }
    return _circleView;
}
- (UIView *)topTimeLine
{
    if (!_topTimeLine) {
        _topTimeLine = [[UIView alloc]init];
        _topTimeLine.backgroundColor =  RGBColor(224, 224, 224);
    }
    return _topTimeLine;
}

- (UIView *)bootomTimeLine
{
    if (!_bootomTimeLine) {
        _bootomTimeLine = [[UIView alloc]init];
        _bootomTimeLine.backgroundColor =  RGBColor(224, 224, 224);
    }
    return _bootomTimeLine;
}
- (UILabel *)operationLabel
{
    if (!_operationLabel) {
        _operationLabel = [[UILabel alloc]init];
        _operationLabel.textColor = RGBColor(51, 51, 51);
    }
    return _operationLabel;
}
@end
